<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>数据监视</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>
    <!-- 准备好一个容器-->
    <div id="root">
        <h1>今天天气很{{isHot ? '炎热': '凉爽'}}</h1>
        <button @click="changeWeather">切换天气</button>
    </div>
</body>
<script type="text/javascript">
    Vue.config.productionTip = false
    const vm = new Vue({
        el: '#root',
        data: {
            isHot: true
        },
        methods: {
            changeWeather() {
                this.isHot = !this.isHot
            }
        },
        watch: {
            // isHot监视的完整写法
            // isHot: {
            //     immediate:true,
            //     handler(newValue, oldValue) {
            //         console.log('isHot的值被人改了', newValue, oldValue)
            //     }
            // }

            //  isHot监视的简写
            isHot(newValue,oldValue){
                console.log('isHot的值被人该了',newValue,oldValue)
            }
        }
    })
    console.log(vm)
</script>

</html>